package com.qf.common.utils;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * --- 业精于勤,荒于嬉 ---
 *
 * @author Song
 * @date 2024/10/30
 * @desc First
 */
public class DateUtils {

    public static String formatLocalDate(LocalDate date, String pattern) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
        return date.format(dateTimeFormatter);
    }

    public static String formatDate(Date date, String pattern) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(date);
    }

    public static Date yesterday() {
        Calendar cal = Calendar.getInstance();
        // 日期的天 加减一个指定值
        cal.add(Calendar.DAY_OF_MONTH, -1);
        return cal.getTime();
    }

}
